#pragma once
#include <string>
#include <conio.h>

#include <Linkcontrol.h>

constexpr int us    = 10;
constexpr int ms    = us * 1000;
constexpr int s     = ms * 1000;


#ifdef _MSC_VER
inline int myGetch() { return _getch(); }
inline void myPutch(int ch) { _putch(ch); }
inline int myStricmp(const char *s1, const char *s2) { return _stricmp(s1, s2); }
inline int myKbhit() { return _kbhit(); }
#else
inline int myGetch() { return getch(); }
inline void myPutch(int ch) { putch(ch); }
inline int myStricmp(const char *s1, const char *s2) { return stricmp(s1, s2); }
inline int myKbhit() { return kbhit(); }
#endif

class CommonOperator {
public:
    // 输出文本
    static void OutputTxt(const char *text, bool line = true);

    // 输出布尔值
    static void OutputBool(int value, const char *pre_txt = "", const char *post_txt = "", bool line = true);

    // 输出整数
    static void OutputDec(int64 value, const char *pre_text = "", const char *post_text = "", bool line = true);

    // 输出浮点数
    static void OutputFloat(double value, const char *pre_text = "", const char *post_text = "", bool line = true);

    // 输出十六进制，保留两位
    static void OutputHex02(byte value, const char *pre_txt = "", const char *post_txt = "", bool line = true);

    // 输出十六进制，保留四位
    static void OutputHex04(ushort value, const char *pre_txt = "", const char *post_txt = "", bool line = true);

    // 输出十六进制，保留八位
    static void OutputHex08(uint value, const char *pre_txt = "", const char *post_txt = "", bool line = true);

    // 输出十六进制，保留十六位
    static void OutputHex16(uint64 value, const char *pre_txt = "", const char *post_txt = "", bool line = true);

    // 输出IPv4地址
    static void OutputIpv4(uint ip, const char *pre_txt = "", const char *post_txt = "", bool line = true);

    // 输出错误信息
    static void OutputErr(KSError error, const char *func_name, const char *comment = "");

    // 输入信息
    static int inputDec(const char* pPreText, int defaultVal);

    // 获取错误信息
    static std::string GetErrorStr(const KSError error);
    // 输入文本
    static char* inputTxt(const char* pPreText, const char* pDefault);
    // 延时
    static void waitTime(uint time);
private:
    static int inputDec(const char* pPreText, const char* pDefault) ;

};

